package com.study.controller;

import com.study.model.dto.StudentQueryDTO;
import com.study.model.entity.StudentDO;
import com.study.result.AjaxResult;
import com.study.service.IStudentService;
import com.study.utils.systemlog.SystemLogAOP;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;


/**
 * 学生 Controller
 */
@RestController
@RequestMapping("/info")
public class StudentController {

    @Resource
    private IStudentService studentService;

    /**
     * 获取学生信息
     */
    @SystemLogAOP
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Long id) {
        return studentService.selectStudentById(id);
    }

    /**
     * 获取学生列表
     */
    @SystemLogAOP
    @GetMapping("/list")
    public AjaxResult list(StudentQueryDTO studentQueryDTO) {
        return studentService.selectStudentList(studentQueryDTO);
    }

    /**
     * 新增
     */
    @SystemLogAOP
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody StudentDO studentDO) {
        return studentService.insertStudent(studentDO);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public AjaxResult edit(@Validated @RequestBody StudentDO studentDO) {
        return studentService.updateStudent(studentDO);
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    public AjaxResult remove(Long id) {
        return studentService.deleteStudentById(id);
    }

    /**
     * 批量删除
     */
    @PostMapping("/delete")
    public AjaxResult delete(Long[] ids) {
        return studentService.deleteStudentByIds(ids);
    }

}
